package onlinejudge.util;

import onlinejudge.complier.CComplier;
import onlinejudge.complier.CplusplusComplier;
import onlinejudge.complier.JavaComplier;
import onlinejudge.vo.ProblemVo;

public class ComplierUtil {
	
	public static String cComplierjudge(String path,ProblemVo problem) {
		String outputData=null;
		String proError=null;
		boolean runFlag=true;
		//第一次评测
		CComplier cComplier=new CComplier(path, problem.getInputItema());
		cComplier.complier();
		proError=cComplier.getErrorMsg();
		if(proError!=null&&!proError.equals("")) {
			outputData=proError;
			runFlag=false;
		}else {
			outputData=cComplier.getOutputData();
			outputData = outputData.substring(0,outputData.length() - 1);
		}
		if(!runFlag) return "comliper_error";
		else {
			if(!outputData.equals(problem.getOutputItema())) {
				return "res_error";
			}
		}
		//第二次评测
		CComplier cComplier2=new CComplier(path, problem.getInputItemb());
		cComplier2.complier();
		proError=cComplier2.getErrorMsg();
		if(proError!=null&&!proError.equals("")) {
			outputData=proError;
			runFlag=false;
		}else {
			outputData=cComplier2.getOutputData();
			outputData = outputData.substring(0,outputData.length() - 1);
		}
		if(!runFlag) return "comliper_error";
		else {
			if(!outputData.equals(problem.getOutputItemb())) {
				return "res_error";
			}
		}
		//第三次评测
		CComplier cComplier3=new CComplier(path, problem.getInputItemc());
		cComplier3.complier();
		proError=cComplier3.getErrorMsg();
		if(proError!=null&&!proError.equals("")) {
			outputData=proError;
			runFlag=false;
		}else {
			outputData=cComplier3.getOutputData();
			outputData = outputData.substring(0,outputData.length() - 1);
		}
		if(!runFlag) return "comliper_error";
		else {
			if(!outputData.equals(problem.getOutputItemc())) {
				return "res_error";
			}
		}
		return "success";
	}
	
	public static String cppComplierjudge(String path,ProblemVo problem) {
		String outputData=null;
		String proError=null;
		boolean runFlag=true;
		//第一次评测
		CplusplusComplier cplusplusComplier=new CplusplusComplier(path, problem.getInputItema());
		cplusplusComplier.complier();
		proError=cplusplusComplier.getErrorMsg();
		if(proError!=null&&!proError.equals("")) {
			outputData=proError;
			runFlag=false;
		}else {
			outputData=cplusplusComplier.getOutputData();
			outputData = outputData.substring(0,outputData.length() - 1);
		}
		if(!runFlag) return "comliper_error";
		else {
			if(!outputData.equals(problem.getOutputItema())) {
				return "res_error";
			}
		}
		//第二次评测
		CplusplusComplier cplusplusComplier2=new CplusplusComplier(path, problem.getInputItemb());
		cplusplusComplier2.complier();
		proError=cplusplusComplier2.getErrorMsg();
		if(proError!=null&&!proError.equals("")) {
			outputData=proError;
			runFlag=false;
		}else {
			outputData=cplusplusComplier2.getOutputData();
			outputData = outputData.substring(0,outputData.length() - 1);
		}
		if(!runFlag) return "comliper_error";
		else {
			if(!outputData.equals(problem.getOutputItemb())) {
				return "res_error";
			}
		}
		//第三次评测
		CplusplusComplier cplusplusComplier3=new CplusplusComplier(path, problem.getInputItemc());
		cplusplusComplier3.complier();
		proError=cplusplusComplier3.getErrorMsg();
		if(proError!=null&&!proError.equals("")) {
			outputData=proError;
			runFlag=false;
		}else {
			outputData=cplusplusComplier3.getOutputData();
			outputData = outputData.substring(0,outputData.length() - 1);
		}
		if(!runFlag) return "comliper_error";
		else {
			if(!outputData.equals(problem.getOutputItemc())) {
				return "res_error";
			}
		}
		return "success";
	}
	
	public static String javaComplierjudge(String path,ProblemVo problem) {
		String outputData=null;
		String proError=null;
		boolean runFlag=true;
		//第一次评测
		JavaComplier javaComliper=new JavaComplier(path, problem.getInputItema());
		javaComliper.complier();
		proError=javaComliper.getErrorMsg();
		if(proError!=null&&!proError.equals("")) {
			outputData=proError;
			runFlag=false;
		}else {
			outputData=javaComliper.getOutputData();
			outputData = outputData.substring(0,outputData.length() - 1);
		}
		if(!runFlag) return "comliper_error";
		else {
			if(!outputData.equals(problem.getOutputItema())) {
				return "res_error";
			}
		}
		//第二次评测
		JavaComplier javaComliper2=new JavaComplier(path, problem.getInputItemb());
		javaComliper2.complier();
		proError=javaComliper2.getErrorMsg();
		if(proError!=null&&!proError.equals("")) {
			outputData=proError;
			runFlag=false;
		}else {
			outputData=javaComliper2.getOutputData();
			outputData = outputData.substring(0,outputData.length() - 1);
		}
		if(!runFlag) return "comliper_error";
		else {
			if(!outputData.equals(problem.getOutputItemb())) {
				return "res_error";
			}
		}
		//第三次评测
		JavaComplier javaComliper3=new JavaComplier(path, problem.getInputItemc());
		javaComliper3.complier();
		proError=javaComliper3.getErrorMsg();
		if(proError!=null&&!proError.equals("")) {
			outputData=proError;
			runFlag=false;
		}else {
			outputData=javaComliper3.getOutputData();
			outputData = outputData.substring(0,outputData.length() - 1);
		}
		if(!runFlag) return "comliper_error";
		else {
			if(!outputData.equals(problem.getOutputItemc())) {
				return "res_error";
			}
		}
		return "success";
	}
}
